package com.xz.example.model.dark_model;

import com.xz.example.model.simple_model.Attachment;

import java.io.*;

/**
 * @author 张志航     
 * @version V1.0.0
 * @projectName design_mode
 * @title     Logger   
 * @package    com.xz.example.model  
 * @date   2019/12/2 10:09  
 * @explain
 */
public class DarkWeeklReport implements Serializable{

    private DarkAttachment attachment; // 附件，一般可以有多个（用list来表示）
    private String name;
    private String date;
    private String content;

    public DarkAttachment getAttachment() {
        return attachment;
    }

    public void setAttachment(DarkAttachment attachment) {
        this.attachment = attachment;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    // 使用序列化实现深克隆
    // 首先使用需要劣化将对象写入到流中,然后使用反序列化将对写的从流中获取,由于在序列化时一个对象的成员会伴随着该对象写入到流中,
    // 反序列化时将得到一个包含成员对象的新对象,因此可以采用序列化与反序列化实现深克隆
    public DarkWeeklReport deepClone() throws IOException, ClassNotFoundException {
        // 将对象写入到流中
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(outputStream);
        oos.writeObject(this);
        // 将对象从流中取出
        ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(inputStream);
        return (DarkWeeklReport) ois.readObject();
    }

    @Override
    public String toString() {
        return "WeeklyReport{" +
                "attachment=" + attachment +
                ", name='" + name + '\'' +
                ", date='" + date + '\'' +
                ", content='" + content + '\'' +
                '}';
    }
}
